package com.bjzsly.star3.xyh;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.bjzsly.star3.xyh.plugin.PGPlugiUtil;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
import io.dcloud.PandoraEntryActivity;

/**
 * Created by Administrator on 2017/12/24.
 */

public class MainActivity extends PandoraEntryActivity {

    private  Context mContext;
    public static QQShareListener qqShareListener;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = MainActivity.this;
        PGPlugiUtil.actContext = mContext;
        qqShareListener = new QQShareListener();
    }

//    public void sharewxcircle(View v){
//        shareWxTQb("http://blog.csdn.net/First_CooMan/article/details/69367519");
//
//    }
//    private String appendSchemeUrl(String url, String scheme, String host) {
////        if (!TextUtils.isEmpty(url) && !TextUtils.isEmpty(scheme) && !TextUtils.isEmpty(host)) {
////            if (url.contains("?")) {
////                url += "&";
////            } else {
////                url += "?";
////            }
////            url += ConstanceValue.ACTIVITY_SCHEME + "=" + scheme;
////            url += "&" + ConstanceValue.ACTIVITY_HOST + "=" + host;
////        }
////        Log.e("1234", url + "");
//        return url;
//
//    }
//    public void shareWxTQb(String url) {
//        try {
//            if (DeviceUtil.isAppInstall(this, ConstanceValue.QQ_BROWSER_PKG)) {
//                String scheme = DeviceUtil.getMetaValue(this, ConstanceValue.META_SHARE_SCHEME);
//                String host = DeviceUtil.getMetaValue(this, ConstanceValue.META_SHARE_CALL_HOST);
////伪启动
////                Intent tempIntent = new Intent(act, ShareCallBackActivity.class);
////                act.startActivity(tempIntent);
//
//                String tempUrl = appendSchemeUrl(url, scheme, host);
//
//                Intent intent = new Intent(Intent.ACTION_VIEW);
//                intent.setClassName(ConstanceValue.QQ_BROWSER_PKG, ConstanceValue.QQ_BROWSER_MAIN);
//                intent.setData(Uri.parse(tempUrl));
//                intent.addCategory(Intent.CATEGORY_BROWSABLE);
//                this.startActivity(intent);
//            } else {
//                Toast.makeText(this, "请先安装QQ浏览器", Toast.LENGTH_SHORT).show();
//            }
//        } catch (Exception e) {
//            Toast.makeText(this, "请先安装QQ浏览器", Toast.LENGTH_SHORT).show();
//        }
//    }
//
//    public void shareQQZone(String title, String summary, String imgUrl, String targetUrl) {
//        TxShareUtils.getInstance().shareQzone(this, title, summary, imgUrl, targetUrl);
//    }
//
//    public void sharewx(View v){
//        new Thread(){
//            @Override
//            public void run() {
//                super.run();
//                WeChatUtils.configType(MainActivity.this, WeChatUtils.TYPE_SHARE_WX_FRIEDN);
//                TxShareUtils.getInstance().shareFriHtml(MainActivity.this,"hahahaa","我是分享内容","http://baidu.com","http://avatar.csdn.net/5/A/5/1_first_cooman.jpg");
//            }
//        }.start();
//    }
//
//    public void sharecircel(View v){
//
//        new Thread(){
//            @Override
//            public void run() {
//                super.run();
//                WeChatUtils.configType(MainActivity.this, WeChatUtils.TYPE_SHARE_WX_CIRCLE);
//                TxShareUtils.getInstance().shareCirHtml(MainActivity.this,"哈哈哈哈哈啊哈哈","朋友圈分享测试","http://baidu.com","http://avatar.csdn.net/5/A/5/1_first_cooman.jpg");
//
//            }
//        }.start();
//    }
//
//
//    public void shareqq(View v){
//        shareQQ("hahahaa","我是分享内容","http://baidu.com","https://www.baidu.com/s?ie=utf-8&f=3&rsv_bp=1&ch=15&tn=56060048_4_pg&wd=jcvideoplayer&oq=%25E6%259C%25BA%25E5%259C%25BAvip%25E9%2580%259A%25E9%2581%2593%25E8%25B5%2584%25E6%25A0%25BC&rsv_pq=d91432d60005315c&rsv_t=52ff%2BmxbPyEx4EyDFme%2FNedOVaTOzRIYQtP%2BH5%2BhK7Uh7w0ak7mFxsgMVN8yky68LnDGeA&rqlang=cn&rsv_enter=1&inputT=3739&rsv_sug3=26&rsv_sug1=21&rsv_sug7=100&rsv_sug2=0&prefixsug=jcv&rsp=0&rsv_sug4=3739");
//
//
//    }
//
//
//    public void shareQQ(String title, String summary, String imgUrl, String targetUrl) {
////        Log.e("1234", "shareQQ  \n" + title + "\n" + summary + "\n" + imgUrl + "\n" + targetUrl);
////        String url = "http://www.baidu.com";
//        TxShareUtils.getInstance().shareQQ(this, title, summary, imgUrl, targetUrl);
//    }
//
//
//    public void shareWxFriend(String title, String desc, String url,String urll) {
//        WeChatUtils.configType(this, WeChatUtils.TYPE_SHARE_WX_FRIEDN);
//        TxShareUtils.getInstance().shareFriHtml(this, title, desc, url,urll);
//    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Tencent.onActivityResultData(requestCode,resultCode,data,qqShareListener);
    }



    private class QQShareListener implements IUiListener
    {
        @Override
        public void onCancel() {
            Toast.makeText(MainActivity.this, R.string.cancel_to_share, Toast.LENGTH_SHORT)
                    .show();
        }

        @Override
        public void onError(UiError uiError) {
            Toast.makeText(MainActivity.this, MainActivity.this.getText(R.string
                            .failed_to_share) + uiError.errorMessage + "\n" +uiError.errorDetail,
                    Toast.LENGTH_SHORT)
                    .show();
        }

        @Override
        public void onComplete(Object o) {
            Toast.makeText(MainActivity.this, R.string.success_to_share, Toast.LENGTH_SHORT)
                    .show();
        }
    }




}
